import { Injectable, UseFilters } from '@nestjs/common';
import { CreateMoviesEpisodeDto } from './dto/create-movies-episode.dto';
import { UpdateMoviesEpisodeDto } from './dto/update-movies-episode.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { MoviesEpisodeEntity } from 'src/modules/admin/movies-episode/entities/movies-episode.entity';
import { Repository } from 'typeorm';
import { throwHttp } from 'src/utlis';
import { HttpExceptionFilter } from 'src/common/http-exception.filter';

@Injectable()
export class MoviesEpisodeService {
  constructor(
    @InjectRepository(MoviesEpisodeEntity)
    private readonly moviesEpisodeRepository: Repository<MoviesEpisodeEntity>,
  ) { }
  /** 获取电影剧情列表 */
  @UseFilters(new HttpExceptionFilter())
  async getMoviesEpisode(movieId: number) {
    try {
      const data = await this.moviesEpisodeRepository.find({
        where: {
          movies: { id: movieId }
        },
        order: { episodeNumber: 'ASC', createDate: 'DESC', },
      });
      return data
    } catch (error) {
      throwHttp(error.message);
    }
  }
  /** 获取电影剧情详情 */
  @UseFilters(new HttpExceptionFilter())
  async getMoviesEpisodeInfo(id: number) {
    try {
      const data = await this.moviesEpisodeRepository.find({
        where: {
          id
        },
        cache: true,
      });
      return data
    } catch (error) {
      throwHttp(error.message);
    }
  }
}
